package com.titar.robot.ui.dialog;

import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.TextView;

import com.titar.robot.R;

import androidx.annotation.Nullable;


/**
 * @project： Timo
 * @package： com.timotech.watch.timo.ui.dialog
 * @class: ComfirmDialogActivity
 * @author: 陆伟
 * @Date: 2017/7/31 18:12
 * @desc： TODO
 */

public class ComfirmDialogActivity extends DialogActivity implements View.OnClickListener {
    private Intent positiveIntent;
    private Intent negtiveIntent;

    public static void show(Context context, String textContent, Intent positiveIntent, Intent negtiveIntent) {
        Context appContext = context.getApplicationContext();
        Intent intent = new Intent(context, ComfirmDialogActivity.class);
        intent.putExtra("content", textContent);
        intent.putExtra("positive_intent", positiveIntent);
        intent.putExtra("negtive_intent", negtiveIntent);
        intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
        appContext.startActivity(intent);
    }


    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.dialog_comfirm);
        TextView contentTextView = (TextView) findViewById(R.id.tv_content);
        findViewById(R.id.btn_cancel).setOnClickListener(this);
        findViewById(R.id.btn_ok).setOnClickListener(this);

        Intent intent = getIntent();
        String contentText = intent.getStringExtra("content");
        positiveIntent = (Intent) intent.getParcelableExtra("positive_intent");
        negtiveIntent = (Intent) intent.getParcelableExtra("negtive_intent");
        contentTextView.setText(contentText);
    }

    @Override
    public void onClick(View v) {
        switch (v.getId()) {
            case R.id.btn_cancel:
                onCLickCancel(v);
                break;
            case R.id.btn_ok:
                onCLickOk(v);
                break;
        }
        finish();
    }

    private void onCLickCancel(View v) {
        if (negtiveIntent != null) {
            startActivity(negtiveIntent);
        }
    }

    protected void onCLickOk(View v) {
        if (positiveIntent != null) {
            startActivity(positiveIntent);
        }
    }
}
